package com.hsj.demo;

import com.hsj.threadpool.ThreadPoolExecutorUtils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/****
 * 视频去重处理
 */
public class VideoFingerprintTest {

    //执行成功0,失败1
    private static int CODE_SUCCESS = 0;
    private static int CODE_FAIL = 1;

    public static void main(String[] args) {

        String inPath = "D:\\BaiduNetdiskDownload\\1\\10.mp4";
        String outPath = "D:\\BaiduNetdiskDownload\\1\\10-out.mp4";
        StringBuilder stb = new StringBuilder();
        stb.append(" -i ");
        stb.append(inPath);
        stb.append(" -vf mpdecimate,setpts=N/FRAME_RATE/TB -map 0:v ");
        stb.append(outPath);
        System.out.println(stb.toString());

        //异步执行，获取执行结果code
        CompletableFuture<Integer> completableFutureTask = CompletableFuture.supplyAsync(() -> {
            System.out.println("开始执行去重命令");
            return FfmpegCmdTest.cmdExecut(stb.toString());
        }, ThreadPoolExecutorUtils.pool);

        //获取执行结果
        //code=0表示正常
        try {
            System.out.println(String.format("获取最终执行结果:%s", completableFutureTask.get() == CODE_SUCCESS ? "成功！" : "失败！"));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

}
